3867. Lazy Misha

 

Mishka arranged to play football with his friends and was already about to leave home, but his mother stopped him. She said that before he could go out to play, Mishka needed to help around the house. His mother offered him a choice of one of three tasks: either wash the dishes, vacuum the apartment, or play with his little sister Marinka while his mom goes to the store. Mishka estimated how much time each task would take:

·        Washing the dishes will take t1 seconds

·        Vacuuming the apartment can be done in t2 seconds

·        Playing with Marinka will take t3 seconds

It is clear that Mishka will choose the task that takes the least time. Your program should determine and print this minimum time.

 

Input. Three integers t1, t2, t3 (1 ≤ t1, t2, t3 ≤ 1000).

 

Output. Print the minimum time Mishka needs to complete his mother’s task.

 

Sample input

Sample output

31 15 40

15

 

 

SOLUTION

conditional statement

 

Algorithm analysis

Mishka needs to choose the task that will take the least time. In other words, it is required to calculate the value of min(t1, t2, t3).

 

Algorithm implementation

Read the input data.

 

scanf("%d %d %d",&t1,&t2,&t3);

 

Compute the minimum among t1, t2, t3.

 

min = t1;

if (t2 < min) min = t2;

if (t3 < min) min = t3;

 

Print the answer.

 

printf("%d\n",min);

 

Java implementation

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int a = con.nextInt();

    int b = con.nextInt();

    int c = con.nextInt();

 

    int res = a;

    if (b < res) res = b;

    if (c < res) res = c;

   

    System.out.println(res);

    con.close();

  }

}  

 

Java implementation – Math.min

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    int a = con.nextInt();

    int b = con.nextInt();

    int c = con.nextInt();

   

    System.out.println(Math.min(Math.min(a,b),c));

    con.close();

  }

}  

 

Python implementation

Read the input data.

 

t1, t2, t3 = map(int,input().split())

 

Compute the minimum among t1, t2, t3.

 

res = min(t1, t2, t3)

 

Print the answer.

 

print(res)